﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.WebPages;
using ALinq.BBS.App_GlobalResources;
using ALinq.BBS.Controllers;
using ALinq.BBS.DataAccess;

namespace ALinq.BBS
{
    public static class PageUrl
    {
        public static MvcHtmlString CreateUserPageLink(this WebViewPage webViewPage, string userName, int pageIndex = 0)
        {
            return webViewPage.Html.RouteLink(userName, new { action = "Member", userName, pageIndex });
        }

        public static MvcHtmlString CreateUserPageLink(this WebViewPage webViewPage, int pageIndex = 0)
        {
            var userName = webViewPage.User.Identity.Name;
            return webViewPage.Html.RouteLink(Label.MySpace, new { action = "Member", userName, pageIndex });
        }

        public static string CreateUserPageUrl(this WebViewPage webViewPage, string userName, int pageIndex = 0)
        {
            return webViewPage.Url.RouteUrl(new { action = "Member", userName, pageIndex });
        }

        public static string CreateUserPageUrl(this WebViewPage webViewPage, int pageIndex = 0)
        {
            var userName = webViewPage.User.Identity.Name;
            return webViewPage.Url.RouteUrl(new { action = "Member", userName, pageIndex });
        }

        public static MvcHtmlString CreatePostPageLink(this WebViewPage webViewPage, int boardID, int forumID,
                                                       string title, int postID, int replyListIndex = 0)
        {
            var obj = new { boardID, forumID, replyListIndex, postID };
            return webViewPage.Html.RouteLink(title, RouteNames.Post, obj);
        }

        public static MvcHtmlString CreatePostPageLink(this WebViewPage webViewPage, Post post, int replyListIndex = 0, string returnUrl = null)
        {
            var boardID = post.Forum.BoardID;
            var forumID = post.ForumID;
            //var postListIndex = 0;
            var postID = post.ID;
            var title = post.Title;

            var obj = new { boardID, forumID, replyListIndex, postID, returnUrl };
            return webViewPage.Html.RouteLink(title, RouteNames.Post, obj);
        }

        public static MvcHtmlString CreatePostFavorPageLink(this WebViewPage page, int pageIndex = 0)
        {
            return page.Html.RouteLink(Label.Favorites, new { action = "PostFavor", pageIndex });
        }

        public static string CreatePostFavorPageUrl(this WebViewPage page, int pageIndex = 0)
        {
            return page.Url.RouteUrl(new { action = "PostFavor", pageIndex });
        }

        public static string CreateLoginPageUrl(this WebViewPage page, string returnUrl = null)
        {
            return page.Url.RouteUrl(new { action = "Login", returnUrl });
        }

        public static string CreateLoginPageUrl(this Controller controller, string returnUrl = null)
        {
            return controller.Url.RouteUrl(new { action = "Login", returnUrl });
        }

        public static MvcHtmlString CreateMyPerssionsPageLink(this WebViewPage page)
        {
            return page.Html.RouteLink(Label.MyPermission, new { action = "MyPermissions" });
        }

        public static string CreateMyPerssionsPageUrl(this WebViewPage page)
        {
            return page.Url.RouteUrl(new { action = "MyPermissions" });
        }

        public static MvcHtmlString CreateControlPanelPageLink(this WebViewPage page)
        {
            return page.Html.RouteLink(Label.ControlPanel, new { action = "ControlPanel" });
        }

        public static MvcHtmlString CreatePostListPageLink(this WebViewPage page, string text, int boardID, int forumID, int postListIndex = 0)
        {
            return page.Html.RouteLink(text, RouteNames.PostList, new { boardID, forumID });
        }

        public static MvcHtmlString CreateDashboardPageLink(this WebViewPage page)
        {
            return page.Html.RouteLink(Label.Dashboard, new { action = "Index", controller = "Admin" });
        }

    }
}